package com.biglead.admin.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biglead.admin.mapper.UserResourceMapper;
import com.biglead.admin.pojo.UmsResource;
import com.biglead.admin.service.UmsResourceService;
import com.biglead.common.pojo.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 后台用户管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service("umsResourceService")
public class UmsResourceServiceImpl extends ServiceImpl<UserResourceMapper, UmsResource> implements UmsResourceService {
    private static final Logger LOGGER = LoggerFactory.getLogger(UmsResourceServiceImpl.class);


    /**
     * 添加资源
     *
     * @param umsResource
     */
    @Override
    public int create(UmsResource umsResource) {
        return 0;
    }

    /**
     * 修改资源
     *
     * @param id
     * @param umsResource
     */
    @Override
    public int update(Long id, UmsResource umsResource) {
        return 0;
    }

    /**
     * 获取资源详情
     *
     * @param id
     */
    @Override
    public UmsResource getItem(Long id) {
        return null;
    }

    /**
     * 删除资源
     *
     * @param id
     */
    @Override
    public int delete(Long id) {
        return 0;
    }

    /**
     * 分页查询资源
     *
     * @param categoryId
     * @param nameKeyword
     * @param urlKeyword
     * @param pageSize
     * @param pageNum
     */
    @Override
    public Page<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum) {
        Page<UmsResource> page = Page.of(pageNum, pageSize);
        //queryWrapper组装查询where条件
        LambdaQueryWrapper<UmsResource> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(nameKeyword)) {
            //查询条件 name 模糊
            queryWrapper.like(UmsResource::getName, nameKeyword);
        }
        if (StringUtils.isNotEmpty(urlKeyword)) {
            //查询条件 name 模糊
            queryWrapper.like(UmsResource::getUrl, urlKeyword);
        }
        if (categoryId != null) {
            queryWrapper.eq(UmsResource::getCategoryId, categoryId);
        }
        //发起查询
        this.page(page, queryWrapper);
        return page;
    }

    /**
     * 查询全部资源
     */
    @Override
    public List<UmsResource> listAll() {
        return null;
    }
}
